//
//  DKLoginPwdLoginView.m
//  DanKU
//
//  Created by 吴斌 on 2023/9/20.
//

#import "DKLoginPwdLoginView.h"
#import "DKLoginPhoneView.h"
#import "DKLoginPwdView.h"
@interface DKLoginPwdLoginView()
@property (nonatomic, strong)DKLoginPhoneView *dk_LoginPhoneView;
@property (nonatomic, strong)DKLoginPwdView *dk_LoginPwdView;
@end
@implementation DKLoginPwdLoginView
-(instancetype)init{
    if(self == [super init]){
        self.backgroundColor = UIColor.whiteColor;
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    WeakSelf(self)
    ///输入账号
    self.dk_LoginPhoneView = [[DKLoginPhoneView alloc] init];
    [self addSubview:self.dk_LoginPhoneView];
    [self.dk_LoginPhoneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.height.equalTo(@(DK_IsWidthScale(50)));
    }];
    self.dk_LoginPhoneView.goCheckPhoneBlock = ^(BOOL isPhoneNull) {//检查输入手机号是否为空
        [weakSelf checkIsNext];
    };
    //输入密码
    self.dk_LoginPwdView = [[DKLoginPwdView alloc] init];
    [self addSubview:self.dk_LoginPwdView];
    [self.dk_LoginPwdView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.top.equalTo(self.dk_LoginPhoneView.mas_bottom).offset(DK_IsWidthScale(20));
        make.height.equalTo(@(DK_IsWidthScale(50)));
    }];
    self.dk_LoginPwdView.goCheckLoginPwdBlock = ^(BOOL isPwdNull) {//检查输入密码是否为空
        [weakSelf checkIsNext];
    };
    UIButton * dk_RegisterBtn = [[UIButton alloc] init];
    [dk_RegisterBtn setTitle:@"Registration" forState:UIControlStateNormal];
    [dk_RegisterBtn setTitleColor:DK_Hex(@"#4566FF") forState:UIControlStateNormal];
    dk_RegisterBtn.titleLabel.font = DK_FONT_Regular(15);
    [dk_RegisterBtn addTarget:self action:@selector(registerPhone) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dk_RegisterBtn];
    [dk_RegisterBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.top.equalTo(self.dk_LoginPwdView.mas_bottom).offset(DK_IsWidthScale(10));
        make.height.equalTo(@(DK_IsWidthScale(21)));
    }];
    UIButton * dk_ForgotPwdBtn = [[UIButton alloc] init];
    [dk_ForgotPwdBtn setTitle:@"Forgot password" forState:UIControlStateNormal];
    [dk_ForgotPwdBtn setTitleColor:DK_Hex(@"#4566FF") forState:UIControlStateNormal];
    dk_ForgotPwdBtn.titleLabel.font = DK_FONT_Regular(15);
    [dk_ForgotPwdBtn addTarget:self action:@selector(forgotPwd) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dk_ForgotPwdBtn];
    [dk_ForgotPwdBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.top.equalTo(self.dk_LoginPwdView.mas_bottom).offset(DK_IsWidthScale(10));
        make.height.equalTo(@(DK_IsWidthScale(21)));
    }];
}
//检查输入手机号/密码，是否勾选协议
- (void)checkIsNext{
    NSString * account = [self.dk_LoginPhoneView getLoginPhone];
    NSString * pwd = [self.dk_LoginPwdView getLoginPwd];
    if(account.length&&pwd.length){
        if(self.goCheckLoginPwdBlock){
            self.goCheckLoginPwdBlock(false);
        }
    }else{
        if(self.goCheckLoginPwdBlock){
            self.goCheckLoginPwdBlock(true);
        }
    }
}
- (void)registerPhone{
    if(self.goAccountRegisterPhoneBlock){
        self.goAccountRegisterPhoneBlock();
    }
}
- (void)forgotPwd{
    if(self.goAccountForgotPwdBlock){
        self.goAccountForgotPwdBlock();
    }
}
- (NSString *)getLoginPhone{
    return [self.dk_LoginPhoneView getLoginPhone];
}
- (NSString *)getLoginPwd{
    return [self.dk_LoginPwdView getLoginPwd];
}
- (void)clearLogin{
    self.dk_LoginPhoneView.dk_RegisterPhoneTextField.text = @"";
    [self.dk_LoginPwdView clearLoginPwd];
}
@end
